package com.ruoyi.web.controller.eamp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.UseApply;
import com.ruoyi.common.annotation.UseLogs;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.eamp.domain.EampCarUse;
import com.ruoyi.eamp.domain.vo.EampCarListVO;
import com.ruoyi.eamp.domain.vo.EampListAndEampUse;
import com.ruoyi.eamp.service.IEampCarUseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eamp.domain.EampCarList;
import com.ruoyi.eamp.service.IEampCarListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 列表Controller
 *
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/list")
public class EampCarListController extends BaseController
{
    @Autowired
    private IEampCarListService eampCarListService;

    @Autowired
    private IEampCarUseService eampCarUseService;

    /**
     * 查询列表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampCarList eampCarList)
    {
        startPage();
        List<EampCarListVO> list = eampCarListService.selectEampCarListList(eampCarList);
        return getDataTable(list);
    }

    /**
     * 导出列表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:export')")
    @Log(title = "列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampCarList eampCarList)
    {
        List<EampCarListVO> list = eampCarListService.selectEampCarListList(eampCarList);
        ExcelUtil<EampCarListVO> util = new ExcelUtil<EampCarListVO>(EampCarListVO.class);
        util.exportExcel(response, list, "列表数据");
    }

    /**
     * 获取列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return success(eampCarListService.selectEampCarListByCarId(carId));
    }

    /**
     * 新增列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:add')")
    // @Log(title = "列表", businessType = BusinessType.INSERT)
    @PostMapping
    @UseLogs
    public AjaxResult add(@RequestBody EampCarList eampCarList)
    {
        return toAjax(eampCarListService.insertEampCarList(eampCarList));
    }

    /**
     * 修改列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:edit')")
    @Log(title = "列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EampCarList eampCarList)
    {
        return toAjax(eampCarListService.updateEampCarList(eampCarList));
    }

    /**
     * 删除列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:list:remove')")
    @Log(title = "列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(eampCarListService.deleteEampCarListByCarIds(carIds));
    }



    //创建人查询
    @PreAuthorize("@ss.hasPermi('eamp:list:createPeople')")
    @PostMapping("/people")
    public TableDataInfo getCreateById(){
        List<SysUser> list = eampCarListService.getCreateById();
        TableDataInfo result= new TableDataInfo();
        result.setCode(200);
        result.setMsg("查询成功");
        result.setRows(list);
        return result;
    }

    //我的用车表
    @PreAuthorize("@ss.hasPermi('eamp:list:UseAndList')")
    @PostMapping("/uselist")
    @UseApply
    public TableDataInfo getUseAndList(EampListAndEampUse eampListAndEampUse) {
        List<EampListAndEampUse> list= eampCarUseService.selectEampCarUseList(eampListAndEampUse);
        TableDataInfo result= new TableDataInfo();
        result.setCode(200);
        result.setMsg("查询成功");
        result.setRows(list);
        return result;

    }





}
